//
//  DoctorCell.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/21.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "DoctorCell.h"
#import "DoctorDTO.h"
#import "FlowerButton.h"

@interface DoctorCell ()

//匹配度图片
@property (nonatomic, strong) UIImageView *mathchV;

//匹配度文字
@property (nonatomic, strong) UILabel *matchTopLab;


//
//@property (nonatomic, strong) UILabel *doctorClassLab;
//
//@property (nonatomic, strong) UILabel *hospitalLab;
//
//@property (nonatomic, strong) FlowerButton *yuyueliangBtn;
//@property (nonatomic, strong) FlowerButton *flowerBtn;
//@property (nonatomic, strong) FlowerButton *jinqiBtn;
//
//@property (nonatomic, strong) UILabel *matchedDegressLab;

/** 背景 View */
@property (nonatomic, strong) UIView *BGView;

@end

@implementation DoctorCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.backgroundColor = RGBCOLOR(241, 242, 242);
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        [self setupUI];
        
    }
    return self;
}

/** 重写DTO */
- (void)setDto:(DoctorDTO *)dto{
    _dto = dto;
    
    self.iconV.image = [UIImage imageNamed:@"illness_img_person.png"];
    
    self.doctorNameLab.text = dto.doctorName;
    self.doctorClassLab.text = dto.doctor_Class;
    self.hospitalLab.text = dto.hospital;
    [self.yuyueliangBtn setTitle:dto.yuyueliangString forState:UIControlStateNormal ];
    [self.flowerBtn setTitle:dto.flowerString forState:UIControlStateNormal ];
    [self.jinqiBtn setTitle:dto.jinqiString forState:UIControlStateNormal ];
    
    self.matchedDegressLab.text  = dto.matchedDegree;

   
}

- (void)setupUI{
    
    //0.
    self.BGView = [[UIView alloc] init];
    self.BGView.backgroundColor = WHITE_COLOR;
    [self addSubview:self.BGView];
    
    //1.
    self.iconV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];
    self.iconV.layer.cornerRadius = 3;
    self.iconV.layer.masksToBounds = YES;
    [self.BGView addSubview:self.iconV];
    
    //2.
    self.doctorNameLab = [[UILabel alloc] init];
    [self.BGView addSubview:self.doctorNameLab];
    self.doctorNameLab.font = FONT(17);
    self.doctorNameLab.text = @"王医生";
    
    //3.
    self.doctorClassLab = [[UILabel alloc] init];
    self.doctorClassLab.font = FONT(16);
    self.doctorClassLab.text = @"副主任医师";
    self.doctorClassLab.textColor = LIGHT_GRAY_COLOR;
     [self.BGView addSubview:self.doctorClassLab];
    
    //4.
    self.hospitalLab = [[UILabel alloc] init];
    self.hospitalLab.font = FONT(16);
    self.hospitalLab.text = @"上海长征医院";
    self.hospitalLab.textColor = LIGHT_GRAY_COLOR;
     [self.BGView addSubview:self.hospitalLab];
    
    
    //5.1
    self.yuyueliangBtn = [[FlowerButton alloc] init];
    [self.yuyueliangBtn setTitleColor:kThemeColor forState:UIControlStateNormal];
    [self.yuyueliangBtn setImage:[UIImage imageNamed:@"yuyueliang"] forState:UIControlStateNormal];
    self.yuyueliangBtn.userInteractionEnabled = NO;
     [self.BGView addSubview:self.yuyueliangBtn];

    //5.2
    self.flowerBtn = [[FlowerButton alloc] init];
    [self.flowerBtn setTitleColor:kThemeColor forState:UIControlStateNormal];
    [self.flowerBtn setImage:[UIImage imageNamed:@"xianhua"] forState:UIControlStateNormal];
    self.flowerBtn.userInteractionEnabled = NO;
     [self.BGView addSubview:self.flowerBtn];
    
    //5.3
    self.jinqiBtn = [[FlowerButton alloc] init];
    [self.jinqiBtn setTitleColor:kThemeColor forState:UIControlStateNormal];
    [self.jinqiBtn setImage:[UIImage imageNamed:@"jinqi"] forState:UIControlStateNormal];
    self.jinqiBtn.userInteractionEnabled = NO;
     [self.BGView addSubview:self.jinqiBtn];
    
//    
//    [self.yuyueliangBtn setTitle:@"10" forState:UIControlStateNormal];
//    [self.flowerBtn setTitle:@"100" forState:UIControlStateNormal];
//    [self.jinqiBtn setTitle:@"30" forState:UIControlStateNormal];
    
    
    //6.1
    self.mathchV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pipeidu"]];
    [self.BGView addSubview:self.mathchV];
    
    //6.2
    self.matchTopLab = [MLLabel labelCreatedWithTitle:@"匹配度" font:13 titleColor:WHITE_COLOR];;
    [self.BGView addSubview:self.matchTopLab];
    
    //6.3 匹配度
    self.matchedDegressLab = [MLLabel labelCreatedWithTitle:@"90%" font:13 titleColor:WHITE_COLOR];
    [self.BGView addSubview:self.matchedDegressLab];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    [self.BGView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(15);
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        
    }];
    
    
    CGFloat iconW = 80;
    
    if (kDevice_Is_iPhone5) {
        
        iconW = 60;
    }
    
    
    [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(iconW, iconW));
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(12);
    }];
    
    [self.doctorNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.iconV.mas_top);
        make.height.mas_equalTo(30);
        make.left.mas_equalTo(self.iconV.mas_right).offset(15);
        
    }];
    
    [self.doctorClassLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.doctorNameLab.mas_top);
        make.height.mas_equalTo(30);
        make.left.mas_equalTo(self.doctorNameLab.mas_right).offset(10);
    }];
    
    [self.hospitalLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.doctorNameLab.mas_bottom);
        make.height.mas_equalTo(30);
        make.left.mas_equalTo(self.iconV.mas_right).offset(10);
    }];
    
    
    CGFloat btnHeight = 15;
    CGFloat btnWight  = 55;
    
    [self.yuyueliangBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.hospitalLab.mas_bottom);
        make.left.mas_equalTo(self.iconV.mas_right).offset(15);
        make.size.mas_equalTo(CGSizeMake(btnWight, btnHeight));
        
    }];
    
    [self.flowerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.yuyueliangBtn.mas_top);
        make.left.mas_equalTo(self.yuyueliangBtn.mas_right).offset(0);
        make.size.mas_equalTo(CGSizeMake(btnWight, btnHeight));
    }];
    
    [self.jinqiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.yuyueliangBtn.mas_top);
        make.left.mas_equalTo(self.flowerBtn.mas_right).offset(0);
        make.size.mas_equalTo(CGSizeMake(btnWight, btnHeight));
    }];
    
    ///  匹配度
    [self.mathchV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(46, 60));
        make.right.mas_equalTo(-35);
        make.top.mas_equalTo(-3);
        
    }];
    
    [self.matchTopLab mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerX.mas_equalTo(self.mathchV.mas_centerX);
        make.top.mas_equalTo(5);
        
    }];
    
    [self.matchedDegressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(self.mathchV.mas_centerX);
        make.top.mas_equalTo(self.matchTopLab.mas_bottom).offset(3);
        
    }];
    
    
    
    
}



@end
